package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 陆小根
 * date: 2022/06/24
 * Description:
 */

@RestController
public class UserController {

  @Autowired
  private UserService userService;

  @RequestMapping("deleteUser.action")
  public @ResponseBody
  String deleteUser(int id){
    String result = userService.deleteUser(id);
    return result;
  }

  @RequestMapping("updateUser.action")
  public @ResponseBody String updateUser(@RequestBody User user){
    String result = userService.updateUser(user);
    return result;
  }

  @RequestMapping("queryUserById.action")
  public @ResponseBody User queryUserById(int id){
    User user = userService.queryUserById(id);
    return user;
  }

  @RequestMapping("addUser.action")
  public @ResponseBody String addUser(@RequestBody User user){
    String result = userService.addUser(user);
    return result;
  }

  @RequestMapping("/queryAll.action")
  public List<User> queryAll() {

    return userService.list();
  }

}
